<?php

namespace App\Admin\Controllers;

use App\Models\Hospital;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use Illuminate\Support\Facades\Storage;

class HospitalController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'Hospital';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Hospital());
        $grid->column('id', __('Id'));
        $grid->column('name', __('医院名称'));
        $grid->column('logo', __('医院logo'))->display(function ($logo) {
            if($logo) {
                return "<img src='".storage::url('')."{$logo}' width='50' height='50'>";
            }
        });
        $grid->column('status', __('状态'))->display(function ($status)  {
            return Hospital::$statusMap[$status];
        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Hospital::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('name', __('医院名称'));
        $show->field('logo', __('医院logo'));
        $show->field('created_at', __('创建时间'));
        $show->field('updated_at', __('更新时间 '));

        return $show;

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Hospital());

        $form->text('name', __('医院名称'));
        $form->image('logo', __('医院logo'));
        $form->textarea('description', __('医院简介'));

        return $form;
    }
}
